﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using FlashCards.Model;

namespace FlashCards.WebApp.Models
{ 
    public class GroupModel
    {
        public int GroupId { get; set; }
        public string Name { get; set; }
        public bool IsHidden { get; set; }
        public int MembersCount { get; set; }
        public int FlashcardSetsCount { get; set; }
        public List<FriendModel> Members { get; set; }
        public List<FlashcardSetModel> FlashcardSets { get; set; }

        public GroupModel(Group group) : this(group, new List<User>(), new List<FlashcardSet>())
        {

        }

        public GroupModel(Group group, List<User> members, List<FlashcardSet> sets)
        {
            GroupId = group.GroupId;
            Name = group.Name;
            IsHidden = group.IsHidden.Value;
            MembersCount = members.Count;
            FlashcardSetsCount = sets.Count;

            Members = new List<FriendModel>();
            foreach (var member in members)
                Members.Add(new FriendModel(member));

            FlashcardSets = new List<FlashcardSetModel>();
            foreach (var set in sets)
                FlashcardSets.Add(new FlashcardSetModel(set));
        }
    }
}